FROM netdata/wget:latest AS builder
ARG HADOOP_VERSION
RUN wget -O /opt/hadoop-${HADOOP_VERSION}.tar.gz https://mirrors.huaweicloud.com/apache/hadoop/common/hadoop-${HADOOP_VERSION}/hadoop-${HADOOP_VERSION}.tar.gz
RUN wget -O /opt/hadoop-huaweicloud-3.1.1-hw-45.jar https://repo.huaweicloud.com/repository/maven/huaweicloudsdk/org/apache/hadoop/hadoop-huaweicloud/3.1.1-hw-45/hadoop-huaweicloud-3.1.1-hw-45.jar
RUN wget -O /opt/jdk-8u192-linux-x64.tar.gz https://repo.huaweicloud.com/java/jdk/8u192-b12/jdk-8u192-linux-x64.tar.gz

FROM ubuntu:20.04
ARG HADOOP_VERSION
# 设置时区
RUN rm -f /etc/localtime && \
    ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo "Asia/Shanghai" > /etc/timezone && \
    export LANG=zh_CN.UTF-8

# 创建用户和用户组，跟yaml编排里的user: 10000:10000
RUN groupadd --system --gid=10000 hadoop && \
    useradd --system --create-home --home-dir /home/hadoop --uid=10000 --gid=hadoop hadoop

# 创建apache目录
RUN mkdir /opt/apache/
COPY ../bootstrap.sh /opt/apache/
COPY --from=builder --chown=hadoop:hadoop --chmod=644 /opt/jdk-8u192-linux-x64.tar.gz /opt/
COPY --from=builder --chown=hadoop:hadoop --chmod=644 /opt/hadoop-${HADOOP_VERSION}.tar.gz /opt/

ENV JAVA_HOME=/opt/jdk1.8.0_192 \
    HADOOP_VERSION=${HADOOP_VERSION} \
    HADOOP_HOME=/opt/apache/hadoop
ENV HADOOP_COMMON_HOME=${HADOOP_HOME} \
    HADOOP_HDFS_HOME=${HADOOP_HOME} \
    HADOOP_MAPRED_HOME=${HADOOP_HOME} \
    HADOOP_YARN_HOME=${HADOOP_HOME} \
    HADOOP_CONF_DIR=${HADOOP_HOME}/etc/hadoop
ENV PATH=${JAVA_HOME}/bin:${HADOOP_HOME}/bin:${PATH}

RUN tar -zxvf /opt/hadoop-${HADOOP_VERSION}.tar.gz -C /opt/apache/ && \
    tar -zxvf /opt/jdk-8u192-linux-x64.tar.gz -C /opt/ && \
    ln -s /opt/apache/hadoop-${HADOOP_VERSION} ${HADOOP_HOME}
RUN rm -rf /opt/hadoop-${HADOOP_VERSION}.tar.gz /opt/jdk-8u192-linux-x64.tar.gz
COPY --from=builder --chown=hadoop:hadoop --chmod=644 /opt/hadoop-huaweicloud-3.1.1-hw-45.jar ${HADOOP_HOME}/share/hadoop/common/lib/
COPY --from=builder --chown=hadoop:hadoop --chmod=644 /opt/hadoop-huaweicloud-3.1.1-hw-45.jar ${HADOOP_HOME}/share/hadoop/tools/lib/